package com.tencent.sr.iris.activity.restapi.activity;

import com.tencent.sr.iris.activity.common.enums.IrisErrorCode;
import com.tencent.sr.iris.activity.common.util.AssertUtils;
import com.tencent.sr.iris.activity.interfaces.client.activity.UserTaskRecordClient;
import com.tencent.sr.iris.activity.interfaces.request.IrisPaginationRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.FlowActivityInfoRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.GetJuniorTaskRecordListRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.ProcessUpdateLimitRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.UserTaskRecordRequest;
import com.tencent.sr.iris.activity.interfaces.response.activity.FlowActivityInfoResponse;
import com.tencent.sr.iris.activity.interfaces.response.activity.UserTaskRecordResponse;
import com.tencent.sr.iris.activity.service.activity.IrisUserTaskRecordService;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 任务参与记录
 *
 * @author nixiaolin
 * @date 2023/2/15 18:02
 */
@Api(tags = "任务参与记录", value = "任务参与记录相关接口")
@RestController
@RequestMapping(value = {"/api/v1/iris/iris-activity-core-service/task/record"})
public class UserTaskRecordController implements UserTaskRecordClient {

    @Resource
    private IrisUserTaskRecordService userTaskRecordService;

    /**
     * 分页查询
     *
     * @author nixiaolin
     * @date 2023/2/15 18:08
     */
    @Override
    @PostMapping("page")
    @ApiOperation(value = "分页查询", httpMethod = "POST")
    public HttpResult<PaginationResponse<UserTaskRecordResponse>> page(
            @Validated @RequestBody IrisPaginationRequest<UserTaskRecordRequest> request) {
        PaginationResponse<UserTaskRecordResponse> response = userTaskRecordService.userTaskPage(request);
        return HttpResult.succ(response);
    }

    @Override
    @PostMapping("getJuniorTaskRecordList")
    @ApiOperation(value = "获取下级任务列表", httpMethod = "POST")
    public HttpResult<PaginationResponse<UserTaskRecordResponse>> getJuniorTaskRecordList(
            @Validated @RequestBody IrisPaginationRequest<GetJuniorTaskRecordListRequest> request) {
        PaginationResponse<UserTaskRecordResponse> response = userTaskRecordService.getJuniorTaskRecordList(request);
        return HttpResult.succ(response);
    }

    @Override
    @PostMapping("queryFlowActivityInfo")
    @ApiOperation(value = "查询余额流水活动信息", httpMethod = "POST")
    public HttpResult<FlowActivityInfoResponse> queryFlowActivityInfo(
            @Validated @RequestBody FlowActivityInfoRequest request) {
        boolean notValid = request.getTaskRecordId() == null && request.getLevelUpReq() == null;
        AssertUtils.isFalse(notValid, IrisErrorCode.PARAM_ERROR);
        FlowActivityInfoResponse response = userTaskRecordService.queryFlowActivityInfo(request);
        return HttpResult.succ(response);
    }

    /**
     * 调高pid的发奖上限处理流程
     * @param request
     * @return
     */
    @Override
    @PostMapping("processUpdateLimit")
    @ApiOperation(value = "调高pid的发奖上限处理流程", httpMethod = "POST")
    public HttpResult<String> processUpdateLimit(
            @Validated @RequestBody ProcessUpdateLimitRequest request) {
        return userTaskRecordService.processUpdateLimit(request);
    }

}
